package org.exercise10.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Stranger
 * @version 1.0
 * @description: TODO
 * @date 2022/12/20 17:11
 */
public abstract class AbstractSubject implements Subject {

    private List<Observer> list;

    public AbstractSubject() {
        this.list = new ArrayList<>();
    }

    @Override
    public void attach(Observer observer) {
        this.list.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        this.list.remove(observer);
    }

    @Override
    public void notice(String message) {
        this.list.forEach(observer -> observer.update(message));
    }
}
